# Maintainer: Felix Yan <felixonmars@archlinux.org>

pkgname=ruby-minitest-rg
pkgver=5.2.0
pkgrel=1
pkgdesc='Colored red/green output for Minitest'
arch=(any)
url='https://github.com/blowmage/minitest-rg'
license=(MIT)
depends=(ruby-minitest)
checkdepends=(ruby-hoe ruby-rake)
options=(!emptydirs)
source=(https://github.com/blowmage/minitest-rg/archive/v$pkgver/$pkgname-$pkgver.tar.gz)
sha256sums=('49a4a7a27ac8be745ea250fce98c1660f39405b2c9d9fa22fafa322207b918d5')

prepare() {
  cd minitest-rg-$pkgver
  sed -i "s/s\\.version = .*/s\\.version = \"$pkgver\"/" minitest-rg.gemspec
  sed -i "s|self.urls        = \['http://blowmage.com/minitest-rg'\]|self.homepage    = 'http://blowmage.com/minitest-rg'|" Rakefile
}

build() {
  local _gemdir="$(gem env gemdir)"
  cd minitest-rg-$pkgver
  gem build minitest-rg.gemspec
  gem install \
    --local \
    --verbose \
    --ignore-dependencies \
    --no-user-install \
    --install-dir "tmp_install/$_gemdir" \
    --bindir "tmp_install/usr/bin" \
    minitest-rg-$pkgver.gem
  find "tmp_install/$_gemdir/gems/" \
    -type f \
    \( \
        -iname "*.o" -o \
        -iname "*.c" -o \
        -iname "*.so" -o \
        -iname "*.time" -o \
        -iname "gem.build_complete" -o \
        -iname "Makefile" \
    \) \
    -delete
  rm -r tmp_install/$_gemdir/cache
}

check() {
  local _gemdir="$(gem env gemdir)"
  cd minitest-rg-$pkgver
  GEM_HOME="tmp_install/$_gemdir" rake || echo "Tests failed"
}

package() {
  cd minitest-rg-$pkgver
  cp -a tmp_install/* "$pkgdir"/
  install -Dm644 LICENSE -t "$pkgdir"/usr/share/licenses/$pkgname/
}
